package net.oov.identify.model;

public class ConfModel extends CheckModelAdapter{

	private Double minConf;
	private FreqCheck fc;
	private Double valueBuffered;
	
	public ConfModel(Double minConf, FreqCheck fc) {
		super();
		this.minConf = minConf;
		this.fc = fc;
	}

	/**
	 * 可信度计算
	 * P(C1C2..Cn)/P(C1)
	 */
	public Double value(StatusNode ct, CharSequence cs) {
		double conf = 1d;
		for(int i=0;i<cs.length();i++){
			int freq = fc.freq(cs.subSequence(i, i+1));
			if(freq==0)continue;
			conf *= ((double)ct.freq())/freq;
		}
		return conf;
	}

	public Boolean check(StatusNode ct, CharSequence cs) {
		Double v = value(ct, cs);
		valueBuffered = v;
		Boolean ret = minConf <= v;
//		if(!ret)wl(cs + ",C:"+v);
		return ret;
	}
	
	public Double value(){
		return this.valueBuffered;
	}

	public static void wl(Object s){
		System.out.println(s);
	}


}
